package com.example.basic.web.controller.common;

import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.service.common.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@Api(value = "文件上传相关操作", tags = {"文件上传"})
@RestController
@RequestMapping("/api/v1/common/file")
public class FileController {
    @Resource
    private FileService fileService;

    /**
     * 房型图片上传
     * @param file 上传的文件
     * @return
     */
    @Log(title = "文件上传", description = "文件上传")
    @ApiOperation(value="文件上传",notes = "文件上传")
    @PostMapping("/fileUpload")
    @ResponseBody
    public Result fileUpload(
            @ApiParam(name = "file", value = "上传的文件",required = true)@RequestPart(value = "file",required = true) MultipartFile file) throws IOException {
        return ResultGenerator.genSuccessResult(fileService.fileUpload(file));
    }

    /**
     * 头像上传
     * @param file 上传的文件
     * @return
     */
    @Log(title = "头像上传", description = "头像上传")
    @ApiOperation(value="头像上传",notes = "头像上传")
    @PostMapping("/avatarUpload")
    @ResponseBody
    public Result avatarUpload(
            @ApiParam(name = "file", value = "上传的文件",required = true)@RequestPart(value = "file",required = true) MultipartFile file) throws IOException {
        return ResultGenerator.genSuccessResult(fileService.avatarUpload(file));
    }
}
